﻿<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>

<div id="createDialog" class="crudDialog">
	<form id="createForm" method="post">
		<div class="form-group">
			<label for="orderId">编号</label>
			<input id="orderId" type="text" class="form-control" name="orderId" maxlength="20" value="${partOrder.orderId}" readonly>
		</div>
		<div class="form-group">
			<label for="name">采购人员</label>
			<input id="name" type="text" class="form-control" name="name" maxlength="32" value="${partOrder.name}">
		</div>
		<div class="form-group">
			<label for="ctime">日期</label>
			<input id="ctime" type="text" class="form-control" name="ctime" maxlength="20" value="${partOrder.ctime}">
		</div>
		<div class="form-group">
			<label for="cremark">备注</label>
			<input id="cremark" type="text" class="form-control" name="cremark" maxlength="20" value="${partOrder.cremark}">
		</div>
		<div class="form-group">
			<input id="orderDetailId" type="hidden" class="form-control" name="orderDetailId" maxlength="20" value="${partOrderDetail.orderDetailId}">
		</div>
		<div class="form-group">
			<span class="type">
				<select id="infoId" name="infoId">
					<option value="0">请选择备件</option>
					<c:forEach var="partInfo" items="${partInfos}">
					<option value="${partInfo.infoId}">${partInfo.name} ${partInfo.model}</option>
					</c:forEach>
				</select>
			</span>
		</div>
		<div class="form-group">
			<label for="number">采购数量</label>
			<input id="number" type="text" class="form-control" name="number" maxlength="20" value="${partOrderDetail.number}">
		</div>
		<div class="form-group">
			<label for="arrivalNum">到货数量</label>
			<input id="arrivalNum" type="text" class="form-control" name="arrivalNum" maxlength="20" value="${partOrderDetail.arrivalNum}">
		</div>
		<div class="form-group">
			<label for="unarrivalNum">未到货数量</label>
			<input id="unarrivalNum" type="text" class="form-control" name="unarrivalNum" maxlength="50" value="${partOrderDetail.unarrivalNum}">
		</div>
		<div class="form-group">
			<label for="price">采购单价</label>
			<input id="price" type="text" class="form-control" name="price" maxlength="50" value="${partOrderDetail.price}">
		</div>
		<div class="form-group">
			<label for="totle">金额</label>
			<input id="totle" type="text" class="form-control" name="totle" maxlength="50" value="${partOrderDetail.totle}">
		</div>
		<div class="form-group">
			<label for="arrivalData">到货日期</label>
			<input id="arrivalData" type="text" class="form-control" name="arrivalData" maxlength="50" value="${partOrderDetail.arrivalData}">
		</div>
		<div class="form-group text-right dialog-buttons">
			<a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
			<a class="waves-effect waves-button" href="javascript:;" onclick="createDialog.close();">取消</a>
		</div>
	</form>
</div>
<script>

laydate.render({
	elem: '#ctime',
	type: 'date',
	format: 'yyyy-MM-dd'
});

laydate.render({
	elem: '#arrivalData',
	type: 'date',
	format: 'yyyy-MM-dd'
});

$(function() {
	var categoryObj = $("#infoId").select2();
	var optionVal = '${partOrderDetail.infoId}';
	categoryObj.val(optionVal).trigger("change");
	categoryObj.change();
});

//格式化日期
function dateFormatter(value) {
	var year = new Date(value).getYear();
	var month = new Date(value).getMonth();
	var day = new Date(value).getDay();
	return new Date(value).toLocaleDateString();
}

function createSubmit() {
    $.ajax({
        type: 'post',
        url: '${basePath}/purchase/order/update/${partOrder.orderId}.do',
        data: $('#createForm').serialize(),
        beforeSend: function() {
            if ($('#infoId').val() == '') {
                $('#infoId').focus();
                return false;
            }
            if ($('#model').val() == '' ) {
                $('#model').focus();
                return false;
            }
            if ($('#spec').val() == '' ) {
                $('#spec').focus();
                return false;
            }
        },
        success: function(result) {
			if (result.code != 1) {
				if (result.data instanceof Array) {
					$.each(result.data, function(index, value) {
						$.confirm({
							animation: 'rotateX',
							closeAnimation: 'rotateX',
							title: false,
							content: value.errorMsg,
							buttons: {
								confirm: {
									text: '确认',
									btnClass: 'waves-effect waves-button waves-light'
								}
							}
						});
					});
				} else {
						$.confirm({
							theme: 'dark',
							animation: 'rotateX',
							closeAnimation: 'rotateX',
							title: false,
							content: result.data.errorMsg || result.data,
							buttons: {
								confirm: {
									text: '确认',
									btnClass: 'waves-effect waves-button waves-light'
								}
							}
						});
				}
			} else {
				updateDialog.close();
				$table.bootstrapTable('refresh');
			}
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
			$.confirm({
				theme: 'dark',
				animation: 'rotateX',
				closeAnimation: 'rotateX',
				title: false,
				content: textStatus,
				buttons: {
					confirm: {
						text: '确认',
						btnClass: 'waves-effect waves-button waves-light'
					}
				}
			});
        }
    });
}
</script>